<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="审批ID" prop="mainId">
      <el-input v-model="dataForm.mainId" placeholder="审批ID"></el-input>
    </el-form-item>
    <el-form-item label="环节ID" prop="detailsId">
      <el-input v-model="dataForm.detailsId" placeholder="环节ID"></el-input>
    </el-form-item>
    <el-form-item label="环节名称" prop="streamMc">
      <el-input v-model="dataForm.streamMc" placeholder="环节名称"></el-input>
    </el-form-item>
    <el-form-item label="环节批注" prop="streamPz">
      <el-input v-model="dataForm.streamPz" placeholder="环节批注"></el-input>
    </el-form-item>
    <el-form-item label="环节状态（进行中、已结束）" prop="streamZt">
      <el-input v-model="dataForm.streamZt" placeholder="环节状态（进行中、已结束）"></el-input>
    </el-form-item>
    <el-form-item label="办理部门ID" prop="operationDeptId">
      <el-input v-model="dataForm.operationDeptId" placeholder="办理部门ID"></el-input>
    </el-form-item>
    <el-form-item label="办理部门名称" prop="operationDeptName">
      <el-input v-model="dataForm.operationDeptName" placeholder="办理部门名称"></el-input>
    </el-form-item>
    <el-form-item label="办理人员ID" prop="operationUserId">
      <el-input v-model="dataForm.operationUserId" placeholder="办理人员ID"></el-input>
    </el-form-item>
    <el-form-item label="办理人员名称" prop="operationUserName">
      <el-input v-model="dataForm.operationUserName" placeholder="办理人员名称"></el-input>
    </el-form-item>
    <el-form-item label="开始时间" prop="startTime">
      <el-input v-model="dataForm.startTime" placeholder="开始时间"></el-input>
    </el-form-item>
    <el-form-item label="结束时间" prop="endTime">
      <el-input v-model="dataForm.endTime" placeholder="结束时间"></el-input>
    </el-form-item>
    <el-form-item label="建立时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="建立时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="editTime">
      <el-input v-model="dataForm.editTime" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="建立部门ID" prop="createDeptId">
      <el-input v-model="dataForm.createDeptId" placeholder="建立部门ID"></el-input>
    </el-form-item>
    <el-form-item label="建立部门" prop="createDeptName">
      <el-input v-model="dataForm.createDeptName" placeholder="建立部门"></el-input>
    </el-form-item>
    <el-form-item label="建立人员ID" prop="createUserId">
      <el-input v-model="dataForm.createUserId" placeholder="建立人员ID"></el-input>
    </el-form-item>
    <el-form-item label="建立人员" prop="createUserName">
      <el-input v-model="dataForm.createUserName" placeholder="建立人员"></el-input>
    </el-form-item>
    <el-form-item label="修改部门ID" prop="editDeptId">
      <el-input v-model="dataForm.editDeptId" placeholder="修改部门ID"></el-input>
    </el-form-item>
    <el-form-item label="修改部门" prop="editDeptName">
      <el-input v-model="dataForm.editDeptName" placeholder="修改部门"></el-input>
    </el-form-item>
    <el-form-item label="修改人员ID" prop="editUserId">
      <el-input v-model="dataForm.editUserId" placeholder="修改人员ID"></el-input>
    </el-form-item>
    <el-form-item label="修改人员" prop="editUserName">
      <el-input v-model="dataForm.editUserName" placeholder="修改人员"></el-input>
    </el-form-item>
    <el-form-item label="数据状态（0删除、1正常）" prop="dataState">
      <el-input v-model="dataForm.dataState" placeholder="数据状态（0删除、1正常）"></el-input>
    </el-form-item>
    <el-form-item label="所属租户" prop="tenantId">
      <el-input v-model="dataForm.tenantId" placeholder="所属租户"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj} from '@/api/admin/sysexaminestream'

    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        dataForm: {
          streamId: 0,
          mainId: '',
          detailsId: '',
          streamMc: '',
          streamPz: '',
          streamZt: '',
          operationDeptId: '',
          operationDeptName: '',
          operationUserId: '',
          operationUserName: '',
          startTime: '',
          endTime: '',
          createTime: '',
          editTime: '',
          createDeptId: '',
          createDeptName: '',
          createUserId: '',
          createUserName: '',
          editDeptId: '',
          editDeptName: '',
          editUserId: '',
          editUserName: '',
          dataState: '',
          tenantId: ''
        },
        dataRule: {
          mainId: [
            { required: true, message: '审批ID不能为空', trigger: 'blur' }
          ],
          detailsId: [
            { required: true, message: '环节ID不能为空', trigger: 'blur' }
          ],
          streamMc: [
            { required: true, message: '环节名称不能为空', trigger: 'blur' }
          ],
          streamPz: [
            { required: true, message: '环节批注不能为空', trigger: 'blur' }
          ],
          streamZt: [
            { required: true, message: '环节状态（进行中、已结束）不能为空', trigger: 'blur' }
          ],
          operationDeptId: [
            { required: true, message: '办理部门ID不能为空', trigger: 'blur' }
          ],
          operationDeptName: [
            { required: true, message: '办理部门名称不能为空', trigger: 'blur' }
          ],
          operationUserId: [
            { required: true, message: '办理人员ID不能为空', trigger: 'blur' }
          ],
          operationUserName: [
            { required: true, message: '办理人员名称不能为空', trigger: 'blur' }
          ],
          startTime: [
            { required: true, message: '开始时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '结束时间不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '建立时间不能为空', trigger: 'blur' }
          ],
          editTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          createDeptId: [
            { required: true, message: '建立部门ID不能为空', trigger: 'blur' }
          ],
          createDeptName: [
            { required: true, message: '建立部门不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '建立人员ID不能为空', trigger: 'blur' }
          ],
          createUserName: [
            { required: true, message: '建立人员不能为空', trigger: 'blur' }
          ],
          editDeptId: [
            { required: true, message: '修改部门ID不能为空', trigger: 'blur' }
          ],
          editDeptName: [
            { required: true, message: '修改部门不能为空', trigger: 'blur' }
          ],
          editUserId: [
            { required: true, message: '修改人员ID不能为空', trigger: 'blur' }
          ],
          editUserName: [
            { required: true, message: '修改人员不能为空', trigger: 'blur' }
          ],
          dataState: [
            { required: true, message: '数据状态（0删除、1正常）不能为空', trigger: 'blur' }
          ],
          tenantId: [
            { required: true, message: '所属租户不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.streamId = id || 0;
        this.visible = true;
        this.canSubmit = true;
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.streamId) {
            getObj(this.dataForm.streamId).then(response => {
                this.dataForm = response.data.data
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.canSubmit = false;
            if (this.dataForm.streamId) {
                putObj(this.dataForm).then(data => {
                    this.$notify.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            } else {
                addObj(this.dataForm).then(data => {
                    this.$notify.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            }
          }
        })
      }
    }
  }
</script>
